package com.ubs.web.diagnostic.imp;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.ubs.ejb.AccountControllerLocal;
import com.ubs.ejb.DiagnosticCompatibleBean;
import com.ubs.ejb.ServiceControllerLocal;
import com.ubs.web.diagnostic.exception.DiagnosticException;

public final class DiagnosticBeanFactory {
	
	private DiagnosticBeanFactory () {
	}

	private static DiagnosticCompatibleBean getBean(String lookupName) throws DiagnosticException {
		InitialContext ic;
		try {
			ic = new InitialContext();
			DiagnosticCompatibleBean bean = (DiagnosticCompatibleBean) ic.lookup(lookupName);
			bean.setDiagnosticMode(true);
			return bean;
		} catch (NamingException e) {
			throw new DiagnosticException(e);
		}
		
	}
	
	public static AccountControllerLocal getAccountControllerBean() throws DiagnosticException {
		return (AccountControllerLocal) getBean("ubs/AccountController");
	}

	public static ServiceControllerLocal getServiceControllerBean() throws DiagnosticException {
		return (ServiceControllerLocal) getBean("ubs/ServiceController");
	}
}
